<%@ page import="com.google.gson.Gson" %><%--
  Created by IntelliJ IDEA.
  User: tangyunyuan
  Date: 2021/4/11
  Time: 15:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<script src="./jsgol/jQuery.js"></script>
<head>
    <title>员工管理</title>
</head>
<body>
<%
    if (session.getAttribute("msg") != null) {
        out.print("<script> alert('" + session.getAttribute("msg") + "'); </script>");
        session.removeAttribute("msg");
    }
%>
<%@include file="Canvas.jsp" %>
<div style="width:800px;height: 700px;border: gray solid 1px;margin:0 auto;background: beige;margin-top: 7%;">
    <%@include file="header.jsp" %>
    <div class="botton" style="width:100%;height:430px;border: red solid 1px;margin: 0px auto;position: relative;">
        <table id="tableData" border="1" style="width: 100%; text-align: center">

        </table>
        <div style="position: absolute;bottom: -50px;">
            <img src="idemge/down.jpg" alt="">
        </div>
        <div style="float: right;font-weight: bold">
            <%
                // 用户总数，用于判断分多少页
                Long userLen = (Long) session.getAttribute("userLen");
                if (userLen != null) {
                    for (int i = 0; i < userLen / 10 + 1; i++) {
                        out.print("<a href='" + request.getContextPath() + "/stalist?page=" + (i + 1) + "'>" + (i + 1) + "</a>");
                    }
                    out.print("共" + (userLen / 10 + 1) + "页");
                }
            %>
        </div>

        <a href="<%=request.getContextPath()%>/AddStaffManagement.jsp"
           style="  position: absolute;bottom: 40px;right: 15px;">添加员工信息</a>
    </div>
</div>
</body>
<script type="text/javascript" src="jsgol/protect.js"></script>
<script>
    var StaffManagement = JSON.parse('<%= new Gson().toJson(session.getAttribute("stalist"))%>');
    console.log(StaffManagement);

    function createTable() {
        var data = $('#tableData');
        data.html(`<tr><th>员工编号</th><th>姓名</th><th>性别</th><th>部门</th><th>工种</th><th>学历</th><th>参加工作时间</th><th>操作</th></tr>`)
        for (let i = 0; i < StaffManagement.length; i++) {
            data.append(`<tr>
                        <td>${StaffManagement[i].A_id ? StaffManagement[i].A_id : '无'}</td>
                        <td>${StaffManagement[i].A_name ? StaffManagement[i].A_name : '无'}</td>
                        <td>${StaffManagement[i].A_sex ? StaffManagement[i].A_sex : '无'}</td>
                        <td>${StaffManagement[i].A_department_id ? StaffManagement[i].A_department_id : '无'}</td>
                        <td>${StaffManagement[i].A_work ? StaffManagement[i].A_work : '无'}</td>
                        <td>${StaffManagement[i].A_education ? StaffManagement[i].A_education : '无'}</td>
                        <td>${StaffManagement[i].A_time ? StaffManagement[i].A_time : '无'}</td>
                         <td><button onclick="">修改</button><button onclick="dele(${i})">删除</button></td>
             </tr>`);

        }
    }

    function dele(index) {
        var sqe = confirm("确定要删除吗?");
        if (sqe == true) {
            location.href = 'stadele?delete=' + StaffManagement[index].A_id;
        }
    }

    createTable();

    $('#navMore').html('> 员工管理');
</script>
<style>
    /*body{*/
    /*    background: url(idemge/12.jpg) no-repeat;*/
    /*}*/
    .botton {
        background: url(idemge/6.png) no-repeat;
        background-size: 100%;
    }
</style>
</html>
